package cn.tedu.charging.order.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class SendController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public String send(String message){
        //1.发送消息 首先我们要组织消息
        byte[] body = message.getBytes(StandardCharsets.UTF_8);
        MessageProperties properties=new MessageProperties();
        //想要发送延迟消息
        //properties.setExpiration("50000");
        Message msg=new Message(body,properties);
        //2.调用api方法将消息发送出去
        rabbitTemplate.send("demo_direct","demo_rk",msg);
        return "ok";
    }
}
